package cn.edu.stu.syllabus.repository.banner.remote;

import cn.edu.stu.syllabus.api.BannerApi;
import cn.edu.stu.syllabus.repository.banner.BannerConverter;
import cn.edu.stu.syllabus.repository.banner.BannerDataSource;
import cn.edu.stu.syllabus.repository.banner.local.BannerInfoEntry;
import cn.edu.stu.syllabus.utils.SchoolHttpResultFun1;
import rx.Observable;
import rx.functions.Func1;

/**
 * Created by daidaijie on 2017/3/13.
 */

public class BannerRemoteDataSource implements BannerDataSource {

    BannerApi mBannerApi;

    public BannerRemoteDataSource(BannerApi bannerApi) {
        mBannerApi = bannerApi;
    }

    @Override
    public Observable<BannerInfoEntry> getBannerInfos() {
        return mBannerApi.getBanner()
                .flatMap(new SchoolHttpResultFun1<BannerInfo>())
                .map(new Func1<BannerInfo, BannerInfoEntry>() {
                    @Override
                    public BannerInfoEntry call(BannerInfo bannerInfo) {
                        return BannerConverter.convert(bannerInfo);
                    }
                });
    }


    @Override
    public void saveBannerInfo(BannerInfoEntry bannerInfoEntries) {
        // 远程仓库无保存方法
    }
}
